package cn.tradewin.advisor.persist.services;

import java.util.List;

import cn.tradewin.advisor.exceptions.DBException;
import cn.tradewin.advisor.persist.model.AccountPerm;
import cn.tradewin.advisor.persist.model.Permissions;
import cn.tradewin.advisor.persist.model.Roles;
import cn.tradewin.advisor.persist.model.Users;

public interface AdvisorSecurityService {
	
	int getMaxRoleId() throws DBException;
	/** find role through specified role id */
	Roles findRole(String id) throws DBException;
	/** add role to Roles master table */
	int addRole(Roles role) throws DBException;
	/** update role for Roles master table */
	int updRole(Roles role) throws DBException;
	/** list all record in Roles master table */
	List<Roles> listAllRoles() throws DBException;
	
	int getMaxPermId() throws DBException;
	/** find permission through specified permission id */
	Permissions findPerm(String id) throws DBException;
	/** add permission to Permission master table */
	int addPerm(Permissions perm) throws DBException;
	/** update permission for permission master table */
	int updPerm(Permissions perm) throws DBException;
	/** list all permissions in permissions master table */
	List<Permissions> listAllPerms() throws DBException;
	
	/** assign permission to specified role */
	List<Permissions> getAuthorizedPermsForRole(String roleId) throws DBException;
	List<Permissions> getAvailablePermsForRole(String roleId) throws DBException;
	int addPermToRole(String roleId, String permId) throws DBException;
	int removePermFromRole(String roleId, String permId) throws DBException;
	
	/*********************************************/
	/*           Account Roles and Perms         */
	/*********************************************/
	/** assign permission to specified account */
	List<AccountPerm> getAuthorizedPermsForAccount(String id) throws DBException;
	List<Permissions> getAvailablePermsForAccount(String id) throws DBException;
	int addPermToAccount(String id, String permId) throws DBException;
	int removePermFromAccount(String id, String permId) throws DBException;
	
	/** assign role to specified account */
	List<Roles> getAssignedRolesForAccount(String id) throws DBException;
	List<Roles> getAvailableRolesForAccount(String id) throws DBException;
	int addRoleToAccount(String id, String roleId) throws DBException;
	int removeRoleFromAccount(String id, String roleId) throws DBException;
//	int removeAllPermsFromAccount(String id) throws DBException;
	
	
	/** get the security user from login account information */
	Users getUser(String accountId) throws DBException;
}
